-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend nullable pointer optimization to library types #36
Conversation
In my opinion, a field should be marked with |
I like this, although I don't believe it can work with |
@kballard that's just the example @thestinger gave me |
@cmr Sure. Which is why I still approve of this RFC overall. I just wanted to make it clear that it did not, in fact, apply to |
We could have "built-in" Then something like a library struct Uniq<T> {
data: NotNull<T>
} |
@huonw note that the rfc has been updated making that obsolete. I'm against adding more lang items for this when the attribute works well, and only affects the (undefined) enum representation. |
It doesn't have to be a proper (I was just mentioning it as a possibility, I don't have any skin in this game. ;P ) |
@huonw If we had struct NotNull<T> {
#[unsafe_not_null]
data: T
} so your That said, I don't think it's necessary. The NotNull aspect here is to enable an optimization, not for any semantics or correctness reasons. |
This is quite an unsafe attribute, so while I'm glad that the word Additionally, this is semi-incompatible with |
It already require unsafe blocks to use the raw pointers. I see no evil On Sun, Apr 6, 2014 at 7:03 PM, Alex Crichton notifications@gh.neting.ccwrote:
|
... an extension of Nullable in trans::adt. On Sun, Apr 6, 2014 at 10:47 PM, Corey Richardson corey@octayn.net wrote:
|
How about changing raw pointers so that they are not allowed to be null? Then, If this is too verbose, one can perhaps rename Option to Opt, or can add a |
Why? What benefit will this bring? Raw pointers are not guaranteed to be valid, so preventing them from being NULL doesn't really add any safety. If you want a valid, non-null pointer, use &T. And if you want to disable borrowck, use transmute() to change the lifetime to 'static. Non-nullable raw pointers only serves to make them even harder to use. |
Well, it brings the benefit that they behave like borrowed pointers, that you don't need a concept of "null" in the language in addition to None, and you can use or not use Option instead of adding this new &T is not just non-null, it's also guaranteed to not alias &mut X and &U for incompatible U (at least in theory/in future) so you can't "just use &T". |
There is an issue in the main rust repo that discussed (and rejected) |
On Wed, Apr 9, 2014 at 8:32 PM, Huon Wilson notifications@gh.neting.ccwrote:
|
Well, this RFC shows there is a need for something like that. A more conservative option is to add a new type, let's call it This is equivalent to this RFC, except it is done cleanly in the type system instead of with an ad-hoc attribute (which means semantics are clear, e.g. the question of who checks whether the value is actually null). Then, one can address as a separate question whether you should then still have *T or whether BTW, I just realized that talking about "null" vs "not null" is probably a mistake, and we should instead think about "valid now" (points to memory valid now) vs "not valid now" (points to usable address space, but there is no allocation there) vs "never valid" (points to unusable parts of the address space, i.e. space reserved for the kernel or > 2^48 on x86-64) vs "tagged as absent" (null pointer in most ABIs). This allows the ABI on embedded systems with no MMU that start physical memory as 0 to declare that an "absent" pointer is not represented as 0, but rather as 0xffffffff (which means Option optimization would represent None as 0xffffffff), and have the language continue working normally. |
isnt' the point of unsafe blocks and *T for catching everything the type system can't express. adding more safety or semantics to unsafe concepts seems contradictory. Wouldn't it be better to leave unsafe {} T as close to C as possible -accept no type system in existance can do *everything, there's always the possibility of tricks or special cases on machines you haven't seen yet.. - but focus on adding more ways to avoid needing unsafe in the first place. (C's power is that it can behave like a super-assembler, and rust's idea of essentially replicating C's ability inside unsafe blocks is great) eg, - enums have eliminated the need for casting, how about a way of expressing enums that allocate the used space only, can't switch to larger variants..
|
At most recent meeting, we decided to close this RFC. This seems like a fine design but there are important and similar cases (i.e., i31) that it doesn't handle. Since it doesn't feel like this problem must be solved urgently, we'd rather hold off from doing anything until we have time to mull a comprehensive solution. That said, if no comprehensive solution seems to work out, this seems like a good outline for a simple solution. |
Another option would be to have a struct like
and then This is a lang item because it will be recognized by ADT. |
The reason to use a field |
Listening vs Listenering
No description provided.